package com.example.iot.queue.message;

import com.alibaba.fastjson.JSONObject;
import com.example.iot.entity.id.EntityId;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.*;

/**
 * 序列化
 * @author ChenXiangpeng
 */
public class SerializeBase implements Serializable {

    public byte[] serialize() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(EntityId.class, new RuleEngineQueueMsg.EntityAdapterFactory<>());
        Gson gson = gsonBuilder.create();
        return gson.toJson(this).getBytes();
    }

}
